package zookeeperJavaAPI;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.junit.Test;

import java.io.IOException;

public class ZKConnect implements Watcher {
    public static final String SERVER_PATH = "101.201.150.42:2181";
    public static final Integer TIME_OUT = 5000;


    @Test
    public static void main(String[] args) throws IOException, InterruptedException {
        /**
         * iP地址多个ip逗号分隔
         * timeout 心跳超时
         * watcher通知事件
         * */
        ZooKeeper zooKeeper = new ZooKeeper(SERVER_PATH, TIME_OUT, new ZKConnect());
        System.out.println(zooKeeper.getState());
        Thread.sleep(2000);
        System.out.println(zooKeeper.getState());
    }


    @Override
    public void process(WatchedEvent watchedEvent) {
        System.out.println("收到了通知");
        System.out.println(watchedEvent);
    }
}
